package 代码记录.指定公司代码练习记录.华为_2024.分值100;

import java.util.*;

/**
 * @author zx
 * @create 2024-02-02 20:05
 * 自己做出来了
 */
public class 开源项目热度榜单_22 {
    /**
     * 做出来了，map的value排序变种
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[5];
        for(int i = 0;i < 5;i++){
            w[i] = sc.nextInt();
        }
        sc.nextLine();
        Map<String, Integer> map = new HashMap<>();
        for(int i = 0;i < n;i++){
            String str = sc.nextLine();
            String[] temp = str.split(" ");
            int[] arr = new int[5];
            for(int j = 1;j < temp.length;j++){
                arr[j - 1] = Integer.parseInt(temp[j]);
            }
            int value = 0;
            for(int j = 0;j < arr.length;j++){
                value += w[j] * arr[j];
            }
            map.put(temp[0],value);
        }
        List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet());
        entries.sort(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if(o1.getValue().equals(o2.getValue())){
                    return o1.getKey().compareTo(o2.getKey());
                }else{
                    return o2.getValue() - o1.getValue();
                }
            }
        });
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey());
        }
    }
}
